//
//  CBArena.m
//  CarsCube
//
//  Created by Wander See on 11-6-12.
//  Copyright 2011年 Tongji Apple Club. All rights reserved.
//

#import "CBArena.h"
#import "GameEngine.h"

#define kPlaneSize 512
#define kGroundName @"Ground"

@implementation CBArena

#pragma mark - Private Methods

- (void)win {
    
}

- (void)loss {
    
}

- (void)addGround {
	CC3MeshNode* ground = [CC3PlaneNode nodeWithName: kGroundName];
	ccColor4F color;
	color.r=255;
	color.g=0;
	color.b=0;
	color.a=1;
	//[ground populateAsCenteredRectangleWithSize:CGSizeMake(500.0, 500.0) andPureColor:Color];
	
	[ground populateAsCenteredRectangleWithSize: CGSizeMake(kPlaneSize, kPlaneSize)
									withTexture: [CC3Texture textureFromFile:  @"Default.png"]
								  invertTexture: YES];
	ground.location = cc3v(500, 300, 0);
	//ground.rotation = cc3v(0, 50, 0);
	[self addChild: ground];
}

#pragma mark - Normal Code

- (NSString *)description {
    return [NSString stringWithFormat:@"%p cars:%@.", 
            self, 
            cars_];
}

/*
 - (id)init {
 self = [super init];
 if (self) {
 [self addGround];
 }
 return self;
 }
 */

- (void)initializeWorld {
    self.isTouchEnabled = YES;
    [self addGround];
}
- (void)dealloc {
    
    [super dealloc];
}

#pragma mark - Events

-(void)ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event {
    CGPoint point=[touch locationInView:[touch view]];
    
	if (point.x < 512) {
        [theCar_ turn:CBDirectionLeft];
		[theCube_ turn:CBDirectionLeft];
        [theInfoPad_ showTurnInfo:CBDirectionLeft];
	} else {
        [theCar_ turn:CBDirectionRight];
        [theCube_ turn:CBDirectionRight];
        [theInfoPad_ showTurnInfo:CBDirectionRight];
	}
}

#pragma mark - Public Methods

- (void)rotateSomex:(float)x y:(float)y z:(float)z {
    CC3MeshNode * grd= (CC3MeshNode *)[[self children] objectAtIndex:0];
    grd.rotation = cc3v(x, y, z);
    
}

@end
